package com.example.lastwork.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@DiscriminatorValue("1")
public class Business extends User {
    @JsonIgnore
    @OneToMany(mappedBy = "business",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL)
    @JsonIgnoreProperties("business")
    @JsonBackReference
    private Set<Shop> shops;

    public Shop createShop(String shopName){
        Shop shop = new Shop();
        shop.setShopName(shopName);
        shop.setBusiness(this);

        shops.add(shop);
        return shop;
    }

    public ShopItem createShopItem(String itemName, Double price, Shop shop,Item item){
        ShopItem shopItem = new ShopItem();
        shopItem.setShopItemName(itemName);
        shopItem.setPrice(price);
        shopItem.setShop(shop);
        shopItem.setItem(item);
        return shopItem;
    }
}
